﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TinyPMS_Jerusalem.Models;

namespace TinyPMS_Jerusalem.Controllers
{
    [HandleError(View="Error")]
    public class ActionLogController : Controller
    {

        //
        // GET: /ActionLog/{actionLogType}/Details/
        [Authorize()]
        public ActionResult Details(string actionLogType)
        {
            ActionLogModel model = new ActionLogModel();
            switch (actionLogType)
            {
                case "Borrow":
                    {
                        ViewData["Result"] = model.GetUserBorrowActionLog(User.Identity.Name).ToArray();      //将获取的对应用户的借出申请记录数组添加到ViewData["Result"]里
                        if (ViewData["Result"] == null)
                            throw new ArgumentException("未找到任何借出记录");
                        ViewData["TypeName"] = "BorrowLog";         //添加对应的记录的类型
                        return View();
                    }
                default:
                    {
                        return RedirectToAction("Index", "Home");
                    }
            }
        }

        // GET: /ActionLog/{actionLogType}/GetPending/
        [Authorize(Roles="Admin")]
        public ActionResult GetPending(string actionLogType)
        {
            ActionLogModel model = new ActionLogModel();
            switch (actionLogType)
            {
                case "Borrow":
                    {
                        ViewData["Result"] = model.GetAllPendingBorrowActionLog().ToArray();          //将获取的待审核的借出申请记录数组添加到ViewData["Result"]里
                        if(ViewData["Result"]==null)
                            throw new ArgumentException("未找到任何需要审核的借出申请");
                        ViewData["TypeName"] = "BorrowApply";              //添加对应的记录的类型
                        return View();
                    }
                default:
                    {
                        return RedirectToAction("Index", "Home");
                    }
            }
        }
    }
}
